//
//  myorderViewController.m
//  lmq
//
//  Created by apple on 2017/3/8.
//  Copyright © 2017年 yuanxin. All rights reserved.
//

#import "myorderViewController.h"
#import "ZJScrollPageView.h"
#import "ForThePaymentViewController.h"
#import "ToSendTheGoodsViewController.h"
#import "ForTheGoodsViewController.h"
#import "SuccessfulDealViewController.h"
#import "AllMyOrderViewController.h"


@interface myorderViewController ()
<ZJScrollPageViewDelegate>
@property(strong, nonatomic)NSArray<NSString *> *titles;
@property(strong, nonatomic)NSArray<UIViewController<ZJScrollPageViewChildVcDelegate> *> *childVcs;

@end

@implementation myorderViewController

- (void)viewDidLoad {
    [super viewDidLoad];self.navigationItem.title = @"我的订单";
    
    UIButton *leftBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame=CGRectMake(0, 0, (22), (22));
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateSelected];
    [leftBtn addTarget:self action:@selector(leftNavItemClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarBtn=[[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem=leftBarBtn;
    
    //必要的设置, 如果没有设置可能导致内容显示不正常
    self.automaticallyAdjustsScrollViewInsets = NO;
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示滚动条
    style.showLine = YES;
    // 颜色渐变
    style.gradualChangeTitleColor = YES;
    style.scrollTitle = YES;
    style.autoAdjustTitlesWidth = YES;
    style.adjustCoverOrLineWidth = YES;
    style.selectedTitleColor = [UIColor colorWithRed:6 / 255.0f green:6 / 255.0f blue:6 / 255.0f alpha:1];
    style.scrollLineColor = [UIColor colorWithRed:6 / 255.0f green:6 / 255.0f blue:6 / 255.0f alpha:1];
    style.segmentHeight = 40;
    self.titles = @[@"全部",
                    @"待付款",
                    @"待发货",
                    @"待收货",
                    @"交易完成",
                    ];
    self.childVcs = [self setupChildVc];
    
    // 初始化
    ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, 64, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64.0) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
    [scrollPageView setSelectedIndex:self.index animated:YES];
    scrollPageView.contentView.scrollView.scrollEnabled = YES;
    [self.view addSubview:scrollPageView];

    // Do any additional setup after loading the view.
}
#pragma mark ----------------ZJScrollPageViewDelegate---------------------
- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}

- (NSArray *)setupChildVc {

    AllMyOrderViewController *vc1 = [AllMyOrderViewController new];
    
    ToSendTheGoodsViewController *vc3 = [ToSendTheGoodsViewController new];
    
    ForTheGoodsViewController *vc4 = [ForTheGoodsViewController new];
    SuccessfulDealViewController *vc5 = [SuccessfulDealViewController new];
    ForThePaymentViewController *vc2 = [ForThePaymentViewController new];
    
    NSArray *childVcs = [NSArray arrayWithObjects:vc1, vc2, vc3, vc4, vc5, nil];
    return childVcs;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    
    UIViewController<ZJScrollPageViewChildVcDelegate> *childVc = reuseViewController;
    
    if (!childVc) {
        childVc = self.childVcs[index];
    }
    
    
    
    
    return childVc;
}
-(void)leftNavItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
